package com.lw.alarm.util.compent;

import org.apache.shiro.util.Assert;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import com.alibaba.druid.util.StringUtils;
import com.xiaoleilu.hutool.lang.Validator;

@Component
public class EmailHelper {
	static final String FROM = "service@lantaiyuan.com";
	@Autowired
	private JavaMailSender mailSender;

	public void sendSimpleMail(String to, String subject, String text) throws Exception {
		SimpleMailMessage message = new SimpleMailMessage();
		Assert.isTrue(Validator.isEmail(to));
		Assert.isTrue(!StringUtils.isEmpty(subject));
		message.setFrom(FROM);
		message.setTo(to);
		message.setSubject(subject);
		message.setText(StringUtils.isEmpty(text) ? "" : text);
		mailSender.send(message);
	}
}
